package com.report.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.report.entity.JsonReport;
import com.report.entity.JsonTaskRecordReport;
import com.report.service.*;
import com.setting.service.UsedService;
import com.utils.JsonResult;

/**
 * @Title: TaskRecordReportController.java
 * @Package com.report.controller
 * @author 孙梦楠
 * @date 2017年9月21日 下午1:03:50
 * @version V1.0.0
 */
@RestController
@RequestMapping(value = "/report")
public class TaskRecordReportController {

	@Autowired
	private UsedService usedservice;

	@Autowired
	private TaskRecordReport_ele_Service taskRecordReport_ele_Service;

	@Autowired
	private TaskRecordReport_water_Service taskRecordReport_water_Service;

	// 表计用电量报表
	@RequestMapping(value = "/task_all_day", method = RequestMethod.POST)
	public JsonResult<Object[][]> recordreportLineday(@RequestBody JsonReport JsonReport,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie) {

		Integer customerid = Integer.valueOf(JsonReport.getOrgvalue());
		String time1 = JsonReport.getBegintime();
		String time2 = JsonReport.getEndtime();
		String status = JsonReport.getStatus();
		String status2 = JsonReport.getStatus2();

		if (status.equals("2") || status.equals("0")) {
			// 判断电水气热 调用不同的service
			switch (opetypecookie) {
			case "1":// 电
				if (status2 == null || status2.equals("示数")) {
					return taskRecordReport_ele_Service.recordreportLine(customerid, "F161", time1, time2, status2);
				} else {
					return taskRecordReport_ele_Service.recordreportLine(customerid, "F161_use", time1, time2, status2);
				}
			case "2":// 水
				if (status2 == null || status2.equals("示数")) {
					return taskRecordReport_water_Service.recordreportLine(customerid, "F221", time1, time2, status2);
				} else {
					return taskRecordReport_water_Service.recordreportLine(customerid, "F221_use", time1, time2,
							status2);
				}
			default:
				return null;
			}

		} else {
			switch (opetypecookie) {
			case "1":// 水
				if (status2 == null || status2.equals("示数")) {
					return usedservice.recordreportLine(customerid, "F161", time1, time2, status2);
				} else {
					return usedservice.recordreportLine(customerid, "F161_use", time1, time2, status2);
				}
			case "2":// 电
				if (status2 == null || status2.equals("示数")) {
					return usedservice.recordreportLine(customerid, "F221", time1, time2, status2);
				} else {
					return usedservice.recordreportLine(customerid, "F221_use", time1, time2, status2);
				}
			default:
				return null;
			}
		}
	}

	// 表计用电量报表_表格
	@RequestMapping(value = "/task_all_table_day", method = RequestMethod.POST)
	public JsonResult<List<JsonTaskRecordReport>> recordreportTableday(@RequestBody JsonReport JsonReport,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		Integer customerid = Integer.valueOf(JsonReport.getOrgvalue());
		String time1 = JsonReport.getBegintime();
		String time2 = JsonReport.getEndtime();
		String status2 = JsonReport.getStatus2();
		if (JsonReport.getStatus().equals("2")) {
			switch (opetypecookie) {
			case "1":// 电
				if (status2 == null || status2.equals("示数")) {
					return taskRecordReport_ele_Service.recordreportTable(customerid, "F161", time1, time2, status2);
				} else {
					return taskRecordReport_ele_Service.recordreportTable(customerid, "F161_use", time1, time2,
							status2);
				}
			case "2":// 水
				if (status2 == null || status2.equals("示数")) {
					return taskRecordReport_water_Service.recordreportTable(customerid, "F221", time1, time2, status2);
				} else {
					return taskRecordReport_water_Service.recordreportTable(customerid, "F221_use", time1, time2,
							status2);
				}
			default:
				return null;
			}

		} else {
			switch (opetypecookie) {
			case "1":// 电
				if (status2 == null || status2.equals("示数")) {
					return usedservice.recordreportTable(customerid, "F161", time1, time2, status2,opetypecookie,languagecookie);
				} else {
					return usedservice.recordreportTable(customerid, "F161_use", time1, time2,
							status2,opetypecookie,languagecookie);
				}
			case "2":// 水
				if (status2 == null || status2.equals("示数")) {
					return usedservice.recordreportTable(customerid, "F221", time1, time2, status2,opetypecookie,languagecookie);
				} else {
					return usedservice.recordreportTable(customerid, "F221_use", time1, time2,
							status2,opetypecookie,languagecookie);
				}
			default:
				return null;
			}
		}
	}
	
	// 表计用电量报表
		@RequestMapping(value = "/task_all_hour", method = RequestMethod.POST)
		public JsonResult<Object[][]> recordreportLinehour(@RequestBody JsonReport JsonReport,
				@CookieValue(value = "opetypecookie", required = false) String opetypecookie) {

			Integer customerid = Integer.valueOf(JsonReport.getOrgvalue());
			String time1 = JsonReport.getBegintime();
			String time2 = JsonReport.getEndtime();
			String status = JsonReport.getStatus();
			String status2 = JsonReport.getStatus2();

			if (status.equals("2") || status.equals("0")) {
				// 判断电水气热 调用不同的service
				switch (opetypecookie) {
				case "1":// 电
					if (status2 == null || status2.equals("示数")) {
						return taskRecordReport_ele_Service.recordreportLine(customerid, "F129", time1, time2, status2);
					} else {
						return taskRecordReport_ele_Service.recordreportLine(customerid, "F129_use", time1, time2, status2);
					}
				case "2":// 水
					if (status2 == null || status2.equals("示数")) {
						return taskRecordReport_water_Service.recordreportLine(customerid, "F221", time1, time2, status2);
					} else {
						return taskRecordReport_water_Service.recordreportLine(customerid, "F221_use", time1, time2,
								status2);
					}
				default:
					return null;
				}

			} else {
				switch (opetypecookie) {
				case "1":// 水
					if (status2 == null || status2.equals("示数")) {
						return usedservice.recordreportLine(customerid, "F129", time1, time2, status2);
					} else {
						return usedservice.recordreportLine(customerid, "F129_use", time1, time2, status2);
					}
				case "2":// 电
					if (status2 == null || status2.equals("示数")) {
						return usedservice.recordreportLine(customerid, "F221", time1, time2, status2);
					} else {
						return usedservice.recordreportLine(customerid, "F221_use", time1, time2, status2);
					}
				default:
					return null;
				}
			}
		}

		// 表计用电量报表_表格
		@RequestMapping(value = "/task_all_table_hour", method = RequestMethod.POST)
		public JsonResult<List<JsonTaskRecordReport>> recordreportTablehour(@RequestBody JsonReport JsonReport,
				@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
				@CookieValue(value = "languagecookie", required = false) String languagecookie) {

			Integer customerid = Integer.valueOf(JsonReport.getOrgvalue());
			String time1 = JsonReport.getBegintime();
			String time2 = JsonReport.getEndtime();
			String status2 = JsonReport.getStatus2();
			if (JsonReport.getStatus().equals("2")) {
				switch (opetypecookie) {
				case "1":// 电
					if (status2 == null || status2.equals("示数")) {
						return taskRecordReport_ele_Service.recordreportTable(customerid, "F129", time1, time2, status2);
					} else {
						return taskRecordReport_ele_Service.recordreportTable(customerid, "F129_use", time1, time2,
								status2);
					}
				case "2":// 水
					if (status2 == null || status2.equals("示数")) {
						return taskRecordReport_water_Service.recordreportTable(customerid, "F221", time1, time2, status2);
					} else {
						return taskRecordReport_water_Service.recordreportTable(customerid, "F221_use", time1, time2,
								status2);
					}
				default:
					return null;
				}

			} else {
				switch (opetypecookie) {
				case "1":// 电
					if (status2 == null || status2.equals("示数")) {
						return usedservice.recordreportTable(customerid, "F129", time1, time2, status2,opetypecookie,languagecookie);
					} else {
						return usedservice.recordreportTable(customerid, "F129_use", time1, time2,
								status2,opetypecookie,languagecookie);
					}
				case "2":// 水
					if (status2 == null || status2.equals("示数")) {
						return usedservice.recordreportTable(customerid, "F221", time1, time2, status2,opetypecookie,languagecookie);
					} else {
						return usedservice.recordreportTable(customerid, "F221_use", time1, time2,
								status2,opetypecookie,languagecookie);
					}
				default:
					return null;
				}
			}
		}

}
